package com.ems.controller.Invigilate.room;

import com.ems.pojo.Invigilate.room.RoomPaper;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.user.User;
import com.ems.service.Invigilate.room.RoomPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2020/2/18
 * @Description: 描述
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有ip跨域
@RequestMapping("/roomPaper")
public class RoomPaperController {
    @Autowired
    @Qualifier("roomPaperService")
    private RoomPaperService roomPaperService;

    //分页查询指定考场中的考题信息
    @RequestMapping("/selectRoomPaperByTrId")
    @ResponseBody
    public ResultData selectRoomPaperByTrId(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);
        List<RoomPaper> list = roomPaperService.selectRoomPaperByTrId(requestData.getMap());
        return ReturnPageResult.AssemblyData(list);
    }

    //分页查询考场中考生的信息，包括
    @RequestMapping("/selectRoomPaperByTrIdAndUser")
    @ResponseBody
    public ResultData selectRoomPaperByTrIdAndUser(@RequestBody RequestData requestData, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user"); //获取用户信息
        ReturnPageResult.setPageHelperInfo(requestData);
        List<RoomPaper> list = roomPaperService.selectRoomPaperByTrIdAndUser(requestData.getMap(),user.getId());
        return ReturnPageResult.AssemblyData(list);
    }



    //编辑考试信息
    @RequestMapping("/updateRoomPaper")
    @ResponseBody
    public ResultData updateRoomPaper(@RequestBody RoomPaper roomPaper){
        roomPaperService.updateRoomPaper(roomPaper);
        return RetunResult.AssemblyData();
    }

    //删除指定的考试信息
    @RequestMapping("/deleteRoomPaper")
    @ResponseBody
    public ResultData deleteRoomPaper(@RequestBody RoomPaper roomPaper){
        roomPaperService.deleteRoomPaper(roomPaper);
        return RetunResult.AssemblyData();
    }

    //在指定考场中添加试题
    @RequestMapping("/addRoomPaper")
    @ResponseBody
    public ResultData addRoomPaper(@RequestBody RoomPaper roomPaper){
        roomPaperService.addRoomPaper(roomPaper);
        return RetunResult.AssemblyData();
    }
}
